﻿using Ionic.Zip;
using System;
using System.IO;

namespace AutoUpdater.Utils
{
    public class ZipHelper
    {
        public static bool UnZip(string zipFilePath, bool overWrite = true)
        {
            try
            {
                string path = Environment.CurrentDirectory + @"\..\";
                if (!File.Exists(zipFilePath))
                {
                    return false;
                }
                //解压  
                using (ZipFile zip = new ZipFile(zipFilePath))
                {
                    if (overWrite)
                    {
                        zip.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently);
                    }
                    else
                    {
                        zip.ExtractAll(path, ExtractExistingFileAction.DoNotOverwrite);
                    }
                }
                //ZipFile.ExtractToDirectory(zipFilePath, path, Encoding.Default);
                return true;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    }

}
